package com.zhaorui.component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
/**
 * 默认插入
 */
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");

        //在第一次插入时createdate&lastdate，时间保持一致
        Date myDate = new Date();
//        this.setFieldValByName ("createtime",myDate,metaObject);
//        this.setFieldValByName ("updattime",myDate,metaObject);
        this.setFieldValByName("del", 0, metaObject);//用于物理删除插入时子增加0
//        this.setFieldValByName ("createDate",myDate,metaObject);
//        this.setFieldValByName ("activityState",0,metaObject);//用于物理删除插入时子弹增加0

    }


    @Override
    public void updateFill(MetaObject metaObject) {//修改时自动触发修改时间
        log.info("start update fill ....");
        Date myDate = new Date();
//        this.setFieldValByName ("updattime",myDate,metaObject);

    }
}
